//
//  HMStatusCell.swift
//  swift-新浪微博0
//
//  Created by 赵玉忠 on 16/9/3.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

// cell里面共有的间距
let HMStatusCellMargin: CGFloat = 10
class HMStatusCell: UITableViewCell {
    
    // 转发微博的高度约束
    var heightCons: Constraint?

    
    var statusViewModel : HMStatusViewModel?{
        didSet{
            // 当前控制器给cell设置数据的时候，cell将数据再次给子视图
            originalView.statusViewModel = statusViewModel
            toolBar.statusViewModel = statusViewModel
            
            // 判断是否有转发微博
            if statusViewModel?.status?.retweeted_status != nil {
                
                retweetView.isHidden = false
                retweetView.statusViewModel = statusViewModel
                
                toolBar.snp_remakeConstraints(closure: { (make) in
                    
                    make.top.equalTo(retweetView.snp_bottom)
                    make.left.right.bottom.equalTo(contentView)
                    make.height.equalTo(35)
                })
                
            }else{
                retweetView.isHidden = true
                
                toolBar.snp_remakeConstraints(closure: { (make) in
                    
                    make.top.equalTo(originalView.snp_bottom)
                    make.left.right.bottom.equalTo(contentView)
                    make.height.equalTo(35)
                })

                
            }
            
        }
    }
    
    
//    // 当前cell对应的模型数据
//    var status : HMStatus?{
//        didSet{
//            nameLabel.text = status?.text
//        }
//    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        // 设置cell的选中样式
        selectionStyle = .none
        
        contentView.backgroundColor = UIColor.lightGray
        // 1. 添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(toolBar)
        contentView.addSubview(retweetView)
        // 2. 添加约束
        originalView.snp_makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            make.top.equalTo(contentView).offset(HMStatusCellMargin)
        }
        
        retweetView.snp_makeConstraints { (make) -> Void in
            make.left.right.equalTo(originalView)
            make.top.equalTo(originalView.snp_bottom)
        }
        
        toolBar.snp_makeConstraints { (make) in
            make.top.equalTo(retweetView.snp_bottom)
            make.left.right.bottom.equalTo(contentView)
            make.height.equalTo(35)
        }
        
    }
    
    
    // MARK: - 懒加载控件
//    lazy var nameLabel:UILabel = {
//        let nameLabel = UILabel(textColor: UIColor.darkGray, fontSize: 14)
//        return nameLabel
//    }()
    lazy var originalView:HMOriginalStatusView = HMOriginalStatusView()
    // 底部的工具条
    private lazy var toolBar:HMStatusToolBar = HMStatusToolBar()
    lazy var retweetView:HMRetweetStatusView = HMRetweetStatusView()


    
    
}
